import { Request, toast } from '../../../utils/util.js'
let request = new Request()
Page({
  data: {
    formData : {
      fee : '',
      slogan: '',
      min_number: '',
      sale_service: '',
      remarks: ''
    },
  },

  input(e) {
    let target = e.currentTarget.dataset.target
    let update = {}
    update['formData.' + target] = e.detail.value
    this.setData(update)
  },

  confirm () {
    let formData = Object.assign({}, this.data.formData)
    for (let k in formData) {
      if (formData[k] === '') {
        toast('请完整填写数据')
        return
      }
    }

    request.post('agent/setrule', res => {
      if(res.success) {
        toast('设置成功')
        wx.navigateBack({
          
        })
      }else{
        toast(res.msg)
      }
    }, formData).showLoading()
  },

  onLoad: function (options) {
    request.get('agent/rule', res => {
      if(res.success) {
        let data = res.data
        if(data) {
          let formData = Object.assign({}, this.data.formData)
          for(let k in data) {
            if (k in formData) {
              formData[k] = data[k]
            }
          }
          this.setData({ formData: formData})
        }
      }
    }).showLoading()
  }
})